class LocationSelection
  
  def initialize(locations, selector, &block)
    @locations = locations.sort
    select(selector)
    yield(self) if block_given?
  end
  
  def selected
    @locations[@select_index] if @select_index
  end
  
  private
  
  def select(selector)
    if @locations.size == 1 
      @select_index =  0 
    else
      @select_index = selector.call(@locations.collect(&:to_s))
    end
  end
end